package com.sservice.banfu.service.impl;

import com.sservice.banfu.e.Tpl;
import com.sservice.banfu.mapper.TplMapper;
import com.sservice.banfu.service.TplService;
import com.sservice.generator.service.AbstractService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Condition;

import java.util.List;

/**
 * Created by byte_su@163.com on 2018/02/05.
 */
@Service
public class TplServiceImpl extends AbstractService<Tpl> implements TplService {

    @Autowired
    private TplMapper tplMapper;


    @Override
    public List<Tpl> reformatContent(List<Tpl> list) {
        for (Tpl tpl : list) {
            tpl.setRemark(tpl.getContent() != null ? new String(tpl.getContent()) : "");
        }
        return list;

    }


    @Override
    public int setHome(Integer id) {
        Condition condition = new Condition(Tpl.class);
        condition.createCriteria().andEqualTo("plain").equals("HOME");
        List<Tpl> list = this.findByCondition(condition);
        if (list.size() > 0) {
            Tpl tpl = list.get(0);
            tpl.setPlain("N/A");
            this.update(tpl);
        }
        Tpl tpl1 = new Tpl();
        tpl1.setId(id);
        tpl1.setPlain("HOME");
        return this.update(tpl1);
    }
}
